package com.example.task1.ui;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.task1.application.MyApplication;

import java.util.List;

public abstract class BaseAdapter<T> extends RecyclerView.Adapter<BaseAdapter<T>.myHolder> {

    protected abstract void setData(List<T> rows);

    protected abstract int getLayout();
    protected abstract Context getContext();

    protected abstract List<T> getData();

    protected abstract void onBind(myHolder holder, T date);

    protected abstract void holder(View view);

    protected void onBind(myHolder holder, T date,int position){

    };


    @NonNull
    @Override
    public myHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(MyApplication.sContext).inflate(getLayout(), parent, false);
        return new myHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull myHolder holder, int position) {
        onBind(holder, getData().get(position));
        onBind(holder, getData().get(position),position);
    }

    @Override
    public int getItemCount() {
        return getData() == null ? 0 : getData().size();
    }

    public class myHolder extends RecyclerView.ViewHolder {
        public myHolder(@NonNull View itemView) {
            super(itemView);
            holder(itemView);
        }
    }
}
